﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Hack.Extensions;
namespace Hack.Forms
{
    public class SplashScreen
    {
        private Form splashForm;
        public void Show(Form form)
        {
            form.WhenNotNull(() =>
            {
                this.splashForm = form;
                Thread th = new Thread(new ThreadStart(DoSplash));
                th.Start();
                Thread.Sleep(3000);
                th.Abort();
                Thread.Sleep(1000);
            
            }).IfFalse(() =>
            {
                throw new NullReferenceException("param Form cant be null"); 
            });
        }
        public void Show(Form form, Action<Form> @action)
        {
            Show(form);
            this.action = @action;
        }
        private Action<Form> action = null;
        public void DoSplash()
        {
            
            splashForm.ShowDialog();
            //object sender = null;
            //EventArgs e = null;

            if (action == null)
            {
                action(splashForm);
            }
            //if (sp.splashCommand == "open")
            //{
            //    openExistingBloodPressureMonitorDatabaseToolStripMenuItem_Click(sender, e);
            //}
            //else
            //{
            //    createNewBPMonitorFileToolStripMenuItem_Click(sender, e);
            //}
        }
    }
}
